
package com.hexinfo.dmpro.sparing.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hexinfo.dmpro.common.utils.CommonConstants;
import com.hexinfo.dmpro.common.utils.StringUtils;
import com.hexinfo.dmpro.sparing.model.SyncCompleteLibrary;
import com.hexinfo.dmpro.sparing.dao.SyncCompleteLibraryMapper;
import com.hexinfo.dmpro.sparing.service.SyncCompleteLibraryService;
import org.springframework.stereotype.Service;

/**
 * 热备全库日志表
 *
 * @author yemw
 * @date 2023-11-30 10:54:05
 */
@Service
public class SyncCompleteLibraryServiceImpl extends ServiceImpl<SyncCompleteLibraryMapper, SyncCompleteLibrary> implements SyncCompleteLibraryService {

    @Override
    public Page queryList(Page page, SyncCompleteLibrary syncCompleteLibrary) {
        LambdaQueryWrapper<SyncCompleteLibrary> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(StrUtil.isNotBlank(syncCompleteLibrary.getTaskId()),SyncCompleteLibrary::getTaskId,syncCompleteLibrary.getTaskId())
                .eq(StrUtil.isNotBlank(syncCompleteLibrary.getTaskState()),SyncCompleteLibrary::getTaskState,syncCompleteLibrary.getTaskState())
                .like(StrUtil.isNotBlank(syncCompleteLibrary.getLibraryTableName()),SyncCompleteLibrary::getLibraryTableName, StringUtils.toLowerCase(syncCompleteLibrary.getLibraryTableName()))
                .apply(StrUtil.isNotBlank(syncCompleteLibrary.getStaDate()),"CREATE_TIME between to_date('" + syncCompleteLibrary.getStaDate() + "','yyyy-MM-dd HH24:MI:SS') and to_date('"+ syncCompleteLibrary.getEndDate() + "','yyyy-MM-dd HH24:MI:SS')")
                .eq(SyncCompleteLibrary::getDel,CommonConstants.STATUS_NORMAL).orderByDesc(SyncCompleteLibrary::getCreateTime);
        Page returnPage = this.baseMapper.selectPage(page, wrapper);
        return returnPage;
    }
}
